/*
 * circularbuffer.c
 *
 *  Created on: Jun 24, 2009
 *      Author: z1083248
 */
#ifndef _CIRCULARBUFFER_H
#define _CIRCULARBUFFER_H

#include "global_types.h"
#include <stdbool.h>

typedef struct circularBuffer
{
   bool isEmpty;

   BUFF_SIZE size;

   BUFF_DATA * ptr_first;
   BUFF_DATA * ptr_end;
   BUFF_DATA * fifo_read_index;

   BUFF_DATA * data;

   /***************************************************************************
    * Function Pointers
    **************************************************************************/

   /*
    * Adds data to the circular buffer;
    *
    * NOTE: this function invalidates the readNext pointer and resets it to the
    *       end of the buffer (since it is a LIFO buffer).
    */
   void (*addToBuffer)(BUFF_DATA inData);

   /*
    * Reads the next item from the buffer; this operates in a LIFO manner;
    * therefore it starts with the newest item and works its way down to the
    * oldest item.
    *
    * returns 0 on success; -1 if index is out of range
    */
   int (*readNext)(BUFF_DATA * const outData);

   /*
    * Prints the circular buffer in LIFO order.
    */
   void (*printLifoBuffer)();

   /*
    * Disposes of objects in memory.
    */
   void (*dispose)();
} circularBufferT;

/*
 * Call to initialize the circular buffer
 */
circularBufferT * initCircularBuffer(BUFF_SIZE size);

#endif
